﻿Type=Class
Version=6
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@

Sub Class_Globals
	Private curtec As Teacher
	Private act As Activity
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(callbackACT As Activity)
	act=callbackACT
End Sub
'如果没有登录就和通用客服聊天,
Public Sub startChatToTec(tarTec As Teacher)
	'判断是否有订单,如果没有的话就和客服聊
	If comm.isLogin Then
		curtec=tarTec
		comm.showProgress("正在连接通信服务器")
		ParseHelper.doPostReqMap(Me,"ordnum",comm.getApi(comm.apiIdx.REQORDNUMBYTEACHER),CreateMap("js_id":curtec.ID),"")
	Else
		comm.TL("尚未登录无法启动即时聊天服务，请登录后使用或者拨打客服电话:"&comm.S_CLIENTPHONENUMBER)
		StartActivity(actLogin)
	End If
End Sub
Public Sub startChatToTecDirectly(tarTec As Teacher)
	'判断是否有订单,如果没有的话就和客服聊
	curtec=tarTec
	Dim ryc As RongyunIMCaller
	ryc.startChatByUser(curtec.mobile,curtec.nickname)
End Sub
Sub JobDone(thj As HttpJob)
	ProgressDialogHide
	If thj.Success Then
		Dim str As String=thj.GetString
		Dim nr As netRes=ParseHelper.getStatusData(str)
			Select thj.JobName
			Case "ordnum"
				If nr.nCode=200 Then
					Dim parser As JSONParser 
					parser.Initialize(str) 
					Dim root As Map = parser.NextObject 
					Dim data As Int
					Try
						 data= root.Get("data") 
					Catch
						data=0
					End Try
					If data>0 Then
						Dim ryc As RongyunIMCaller
						ryc.startChatByUser(curtec.mobile,curtec.nickname)
					Else
						callCommonCustomService
					End If
				Else
					comm.L("获取订单数量失败,直接联系通用客服")
					callCommonCustomService
				End If
			End Select
		
	Else
		comm.TL("网络错误:"&thj.ErrorMessage)
	End If
	thj.Release
End Sub
'如果已经登录则联系专属客服,否则联系通用客服
public Sub callCustomService
	If comm.isLogin And comm.mi.kefu.Length>4 Then
		Dim ryc As RongyunIMCaller
		ryc.startChatByUser2(comm.mi.kefu,"",ryc.CUSTOMER_SERVICE)
	Else
		callCommonCustomService
	End If
	Dim ryc As RongyunIMCaller
	ryc.startChatByUser2(comm.KF_COMMON_ID,"客服",ryc.CUSTOMER_SERVICE)
End Sub
'联系通用客服,不要求登录(但imkit必须登录,暂时无大用)
public Sub callCommonCustomService
	Dim ryc As RongyunIMCaller
	ryc.startChatByUser2(comm.KF_COMMON_ID,"客服",ryc.CUSTOMER_SERVICE)
End Sub